package com.heima.article.controller;

import com.heima.article.service.ApArticleContentService;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApArticleContent;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    private ApArticleService apArticleService;

    @Autowired
    private ApArticleContentService apArticleContentService;

    /**
     * 列表文章分页查询
     */
    @GetMapping(value="/list/{tag}/{page}/{size}")
    public ResponseResult homeList(
            @PathVariable(value = "tag")Integer tag,
            @PathVariable(value = "page")Integer page,
            @PathVariable(value = "size")Integer size
    ){
       return apArticleService.homeList(tag,page,size);
    }

    /**
     * 根据获取的id查询文章详情
     */
    @GetMapping
    public ApArticleContent contentText( Long id){
        return  apArticleContentService.ContentText(id);
    }

    /**
     * 将静态页面的url内容设置回Article的字段：static_url
     */
    @PostMapping
    public void updateContentUrl( String staticUrl,Long id){
        apArticleService.updateContentUrl(staticUrl,id);

    }



}
